<?php
namespace app\customer\controller;
use think\Db;
class Message extends Base{
    public function message_list(){
        $key=input('get.key');
        if (!empty(input('get.fromtime'))) {
            $fromtime=strtotime(input('get.fromtime'));
        }else{
            $fromtime=0;
        }
        if (!empty(input('get.totime'))) {
            $totime=strtotime(input('get.totime'))+86400;
        }else{
            $totime=time();
        }
        $list=Db::name('message')->where('cus_id',session('customer')['id'])->where('state',1)->where('time','>',"{$fromtime}")->where('time','<',"{$totime}")->where('name|tel|email','like',"%{$key}%")->order('id desc')->paginate(10);
        $lists=Db::name('message')->where('cus_id',session('customer')['id'])->where('state',1)->where('time','>',"{$fromtime}")->where('time','<',"{$totime}")->where('name|tel|email','like',"%{$key}%")->select();
        $data=$list->all();
        $this->assign('key',input('get.key'));
        $this->assign('fromtime',input('get.fromtime'));
        $this->assign('totime',input('get.totime'));
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('lists',$lists);
        return $this->fetch();
    }
    public function message_del(){
        $param = input('post.');
        $res= Db::name('message')->where(array('id'=>$param['id']))->update(['state'=>3]);
        return json(['code' => 200,'msg' => '删除成功']);

    }
    public function appoint_list(){
        $key=input('get.key');
        if (!empty(input('get.fromtime'))) {
            $fromtime=strtotime(input('get.fromtime'));
        }else{
            $fromtime=0;
        }
        if (!empty(input('get.totime'))) {
            $totime=strtotime(input('get.totime'))+86400;
        }else{
            $totime=time();
        }
        $list=Db::name('appointment')->where('cus_id',session('customer')['id'])->where('state',1)->where('time','>',"{$fromtime}")->where('time','<',"{$totime}")->where('uname|uphone|uemail|uaddress|uredio|ucheck','like',"%{$key}%")->order('id desc')->paginate(10);
        $lists=Db::name('appointment')->where('cus_id',session('customer')['id'])->where('state',1)->where('time','>',"{$fromtime}")->where('time','<',"{$totime}")->where('uname|uphone|uemail|uaddress|uredio|ucheck','like',"%{$key}%")->select();
        $data=$list->all();
        $this->assign('key',input('get.key'));
        $this->assign('fromtime',input('get.fromtime'));
        $this->assign('totime',input('get.totime'));
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('lists',$lists);
        return $this->fetch();
    }
    public function appoint_del(){
        $param = input('post.');
        $res= Db::name('appointment')->where(array('id'=>$param['id']))->update(['state'=>3]);
        return json(['code' => 200,'msg' => '删除成功']);

    }
}
